package com.meilai.project.controller.web.adMake.service;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.meilai.project.controller.web.adMake.dto.BillAdMakePicsForConfirmDTO;
import com.meilai.project.controller.web.adMake.entity.BillAdMakeSupplierConfirm;
import com.meilai.project.controller.web.adMake.mapper.BillAdMakeSupplierConfirmMapper;
import com.meilai.project.controller.web.adMake.vo.BillAdMakeConfirmWebVO;
import com.meilai.project.controller.web.adMake.vo.BillAdMakeSupplierConfirmVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Set;

/**
 * <p>
 * 制作单-配送 服务实现类
 * </p>
 *
 * @author 张驰
 * @since 2022-08-16
 */
@Service
public class BillAdMakeSupplierConfirmServiceImpl extends ServiceImpl<BillAdMakeSupplierConfirmMapper, BillAdMakeSupplierConfirm> implements BillAdMakeSupplierConfirmService {
    @Transactional
    @Override
    public void deleteByAdMakeId(Long adMakeId) {
        LambdaQueryWrapper<BillAdMakeSupplierConfirm> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(BillAdMakeSupplierConfirm::getBill_ad_make_id, adMakeId);
        remove(wrapper);
    }

    @Override
    public BillAdMakeConfirmWebVO getConfirmVOById(String batchId) {
        return baseMapper.getConfirmVOById(batchId);
    }

    @Override
    public List<BillAdMakeSupplierConfirmVO> confirmVOList(Long adMakeId) {
        return baseMapper.confirmVOList(adMakeId);
    }

    @Override
    public List<BillAdMakePicsForConfirmDTO> getConfirmPicList(Long adMakeId, Set<Long> supplierIds) {
        return baseMapper.getConfirmPicList(adMakeId, supplierIds);
    }

    @Override
    public BillAdMakeSupplierConfirm getConfirmByAdMakeIdAndSupplierId(Long adMakeId, Long supplierId) {
        List<BillAdMakeSupplierConfirm> cons = list(Wrappers.<BillAdMakeSupplierConfirm>lambdaQuery()
                .eq(BillAdMakeSupplierConfirm::getBill_ad_make_id, adMakeId)
                .eq(BillAdMakeSupplierConfirm::getSupplier_id, supplierId));
        if(CollectionUtils.isNotEmpty(cons) && cons.size()==1){
            return cons.get(0);
        }else{
            return null;
        }
    }

    @Override
    public BillAdMakeSupplierConfirm getConfirmByBatchStr(String batchStr) {
        LambdaQueryWrapper<BillAdMakeSupplierConfirm> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(BillAdMakeSupplierConfirm::getBatch_id, batchStr);
        return getOne(wrapper);
    }

    @Override
    public List<BillAdMakeSupplierConfirmVO> getListBySaleIds(List<Long> saleIds) {
        return baseMapper.getListBySaleIds(saleIds);
    }
}
